home *** CD-ROM | disk | FTP | other *** search
- /* UPS_Charge.c */
-
- /* UPS_Charge XFCN for HyperCard
- with LightSpeedC v. 3.01 - 11/22/88
- Copyright 1988 by
- Given a valid UPS zone and package weight, Sam Thornton
- returns the correct UPS freight charge. PO Box 123
- Also supports Federal Express rate chart. Fairfield NE 68938
- (Rates as of 11/88.) Some portions Copyright
- by Symantec and Apple.
- See UPS_Charge.docs for user interface
- Compuserve: 71750,667
- GEnie: S.THORNTON5
-
- NOTE: All 'StringPtr' types in May be copied and
- HyperXCmd.h and glue should distributed for personal
- be dereferenced to type 'Ptr' use without charge only,
- for this to compile properly. except for nominal
- distribution fees. For
- commercial use or
- distribution, contact
- author, above. */
- #include "HyperXCmd.h"
- #include "SetUpA4.h"
- #include "MemoryMgr.h"
- #include "Math.h"
- #include "strings.h"
- #include "stdio.h"
- #include "ctype.h"
- #include "unix.h"
-
- typedef struct _chgs {
- int _charge[71]; /* item 1 is reference code/zone, remaining 70 for weights */
- } _chgs;
-
- static _chgs charge_table[] = {
-
- /* rates are stored as whole numbers, formatted later for return */
-
- 0, /* FEDERAL EXPRESS OVERNIGHT */
- 2025, 2300, 2575, 2850, 3125, 3400, 3675, 3950,
- 4225, 4500, 4625, 4750, 4875, 5000, 5125, 5250,
- 5375, 5500, 5625, 5750, 5875, 6000, 6125, 6250,
- 6375, 6500, 6625, 6750, 6875, 7000, 7125, 7250,
- 7375, 7500, 7625, 7750, 7875, 8000, 8125, 8250,
- 8375, 8500, 8625, 8750, 8875, 9000, 9125, 9250,
- 9375, 9500, 9625, 9750, 9875, 10000, 10125, 10250,
- 10375, 10500, 10625, 10750, 10875, 11000, 11125,
- 11250, 11375, 11500, 11625, 11750, 11875, 12000,
-
- 1, /* FEDERAL EXPRESS 2ND DAY AIR */
- 1150, 1250, 1350, 1450, 1550, 1650, 1750, 1850,
- 1950, 2050, 2150, 2250, 2350, 2450, 2550, 2650,
- 2750, 2850, 2950, 3050, 3150, 3250, 3350, 3450,
- 3550, 3650, 3750, 3850, 3950, 4050, 4150, 4250,
- 4350, 4450, 4550, 4650, 4750, 4850, 4950, 5050,
- 5150, 5250, 5350, 5450, 5500, 5550, 5600, 5650,
- 5700, 5750, 5800, 5850, 5900, 5950, 6000, 6050,
- 6100, 6150, 6200, 6250, 6300, 6350, 6400, 6450,
- 6500, 6550, 6600, 6650, 6700, 6750,
-
- 2, /* UPS SURFACE */
- 134, 136, 144, 153, 162, 171, 180, 189, 198,
- 207, 216, 225, 234, 243, 252, 261, 270, 279,
- 288, 297, 306, 315, 324, 333, 342, 351, 360,
- 369, 378, 387, 395, 403, 411, 419, 427, 435,
- 443, 451, 459, 467, 475, 483, 491, 499, 507,
- 515, 523, 531, 539, 547, 550, 553, 556, 559,
- 562, 565, 568, 571, 574, 577, 580, 583, 586,
- 589, 592, 595, 598, 601, 604, 607,
-
- 3, /* UPS SURFACE */
- 145, 147, 160, 172, 183, 192, 204, 216, 229,
- 241, 255, 268, 280, 293, 305, 318, 331, 343,
- 357, 369, 382, 395, 407, 420, 432, 445, 459,
- 471, 484, 496, 513, 530, 542, 556, 568, 581,
- 595, 607, 620, 632, 646, 659, 671, 685, 697,
- 710, 724, 736, 749, 762, 766, 769, 772, 775,
- 778, 781, 785, 788, 791, 794, 797, 801, 804,
- 808, 811, 814, 817, 820, 823, 826,
-
- 4, /* UPS SURFACE */
- 160, 179, 194, 211, 222, 233, 249, 267, 284,
- 300, 317, 334, 351, 369, 385, 402, 419, 436,
- 453, 470, 487, 504, 521, 538, 554, 572, 589,
- 606, 623, 639, 662, 684, 701, 719, 735, 752,
- 770, 787, 805, 821, 838, 856, 873, 891, 907,
- 925, 942, 959, 977, 993, 998, 1002, 1008, 1012,
- 1016, 1021, 1025, 1029, 1034, 1038, 1042, 1048,
- 1052, 1056, 1061, 1065, 1069, 1074, 1078, 1082,
-
- 5, /* UPS SURFACE */
- 167, 190, 211, 231, 246, 263, 283, 305, 326,
- 347, 370, 391, 413, 434, 456, 478, 499, 521,
- 542, 564, 586, 607, 629, 650, 672, 694, 715,
- 737, 759, 780, 809, 835, 858, 879, 901, 924,
- 945, 968, 989, 1011, 1033, 1055, 1077, 1099,
- 1120, 1143, 1164, 1187, 1208, 1230, 1236, 1241,
- 1247, 1253, 1259, 1264, 1269, 1275, 1280, 1286,
- 1292, 1298, 1303, 1308, 1314, 1319, 1325, 1330,
- 1337, 1342,
-
- 6, /* UPS SURFACE */
- 174, 205, 232, 260, 281, 302, 329, 358, 386,
- 413, 441, 470, 498, 526, 553, 582, 610, 638,
- 667, 694, 722, 750, 779, 807, 834, 863, 891,
- 919, 947, 975, 1011, 1047, 1075, 1104, 1132,
- 1160, 1189, 1218, 1246, 1274, 1303, 1331, 1360,
- 1389, 1417, 1445, 1474, 1503, 1531, 1559, 1566,
- 1573, 1581, 1588, 1595, 1602, 1609, 1616, 1624,
- 1630, 1637, 1644, 1651, 1658, 1666, 1673, 1680,
- 1687, 1694, 1700,
-
- 7, /* UPS SURFACE */
- 183, 220, 255, 289, 317, 344, 378, 412, 447,
- 482, 517, 551, 587, 621, 657, 691, 726, 781,
- 796, 830, 866, 900, 935, 970, 1005, 1039, 1075,
- 1109, 1144, 1179, 1224, 1267, 1303, 1338, 1374,
- 1408, 1444, 1479, 1515, 1550, 1586, 1621, 1656,
- 1691, 1727, 1762, 1798, 1833, 1869, 1903, 1913,
- 1922, 1931, 1940, 1950, 1959, 1968, 1977, 1986,
- 1996, 2005, 2014, 2023, 2033, 2042, 2051, 2060,
- 2069, 2079, 2088,
-
- 8, /* UPS SURFACE */
- 191, 237, 278, 320, 354, 388, 428, 470, 512,
- 553, 596, 638, 680, 722, 764, 806, 848, 890,
- 932, 974, 1016, 1058, 1100, 1142, 1184, 1226,
- 1269, 1310, 1352, 1394, 1448, 1501, 1543, 1586,
- 1628, 1671, 1714, 1756, 1799, 1841, 1884, 1927,
- 1969, 2012, 2054, 2097, 2140, 2182, 2225, 2267,
- 2279, 2289, 2299, 2310, 2321, 2331, 2342, 2352,
- 2363, 2374, 2384, 2394, 2406, 2416, 2426, 2437,
- 2448, 2458, 2469, 2479,
-
- 12, /* UPS 2ND DAY AIR - 48 STATES */
- 300, 400, 500, 600, 650, 750, 850, 950, 1050,
- 1150, 1250, 1350, 1450, 1550, 1650, 1750, 1850,
- 1950, 2000, 2100, 2200, 2300, 2400, 2500, 2600,
- 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400,
- 3500, 3600, 3650, 3750, 3850, 3950, 4050, 4150,
- 4250, 4350, 4450, 4550, 4650, 4750, 4850, 4950,
- 5050, 5050, 5100, 5100, 5150, 5150, 5200, 5200,
- 5250, 5250, 5300, 5300, 5350, 5350, 5350, 5400,
- 5400, 5450, 5450, 5500, 5500,
-
- 14, /* UPS 2ND DAY AIR - ALASKA METRO & HAWAII */
- 500, 650, 750, 900, 1000, 1150, 1250, 1400, 1500,
- 1650, 1750, 1850, 1950, 2050, 2200, 2300, 2400,
- 2500, 2600, 2750, 2850, 2950, 3100, 3200, 3300,
- 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100,
- 4200, 4300, 4400, 4500, 4550, 4600, 4650, 4700,
- 4750, 4800, 4850, 4950, 5050, 5150, 5250, 5350,
- 5450, 5550, 5600, 5650, 5700, 5750, 5800, 5850,
- 5900, 5950, 6000, 6050, 6050, 6100, 6100, 6150,
- 6150, 6200, 6200, 6250, 6250,
-
- 15, /* UPS 2ND DAY AIR PUERTO RICO */
- 600, 700, 800, 900, 1000, 1100, 1200, 1300,
- 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100,
- 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900,
- 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700,
- 3800, 3900, 4000, 4050, 4150, 4250, 4350, 4450,
- 4500, 4550, 4600, 4700, 4800, 4900, 5000, 5100,
- 5200, 5300, 5300, 5350, 5350, 5400, 5400, 5450,
- 5450, 5500, 5500, 5550, 5550, 5600, 5600, 5600,
- 5650, 5650, 5700, 5700, 5750, 5750,
-
- 16, /* UPS 2ND DAY AIR - ALASKA RURAL */
- 1250, 1350, 1450, 1550, 1650, 1750, 1900, 2000,
- 2100, 2200, 2250, 2350, 2450, 2600, 2700, 2800,
- 2900, 3000, 3100, 3250, 3350, 3450, 3550, 3650,
- 3750, 3900, 4000, 4100, 4200, 4300, 4400, 4550,
- 4650, 4750, 4850, 4950, 5050, 5150, 5250, 5350,
- 5450, 5550, 5650, 5750, 5900, 6000, 6100, 6200,
- 6300, 6400, 6450, 6450, 6500, 6550, 6550, 6600,
- 6600, 6650, 6650, 6700, 6700, 6750, 6750, 6800,
- 6850, 6850, 6900, 6900, 6950, 6950,
-
- 22, /* UPS 1ST DAY AIR - 48 STATES */
- 1150, 1250, 1350, 1450, 1550, 1650, 1800, 1900,
- 2000, 2100, 2200, 2300, 2400, 2550, 2650, 2750,
- 2850, 2950, 3050, 3200, 3300, 3400, 3500, 3600,
- 3700, 3850, 3950, 4050, 4150, 4250, 4350, 4500,
- 4600, 4700, 4800, 4900, 5000, 5100, 5250, 5350,
- 5450, 5550, 5650, 5750, 5900, 6000, 6100, 6200,
- 6300, 6400, 6450, 6450, 6500, 6550, 6550, 6600,
- 6600, 6650, 6650, 6700, 6700, 6750, 6750, 6800,
- 6850, 6850, 6900, 6900, 6950, 6950,
-
- 24, /* UPS 1ST DAY AIR - ALASKA & HAWAII */
- 1300, 1450, 1550, 1700, 1800, 1900, 2050, 2150,
- 2300, 2400, 2500, 2600, 2700, 2850, 3000, 3100,
- 3200, 3300, 3400, 3550, 3650, 3750, 3850, 3950,
- 4050, 4200, 4300, 4400, 4500, 4600, 4700, 4850,
- 4950, 5050, 5150, 5250, 5350, 5450, 5600, 5700,
- 5800, 5900, 6000, 6100, 6250, 6350, 6450, 6550,
- 6650, 6750, 6800, 6800, 6850, 6900, 6900, 6950,
- 6950, 7000, 7000, 7050, 7050, 7100, 7100, 7150,
- 7200, 7200, 7250, 7250, 7300, 7300,
-
- 25, /* UPS 1ST DAY AIR - PUERTO RICO */
- 1500, 1600, 1750, 1850, 1950, 2050, 2200, 2350,
- 2450, 2550, 2650, 2750, 2850, 3000, 3100, 3200,
- 3300, 3400, 3500, 3650, 3750, 3850, 3950, 4050,
- 4150, 4300, 4400, 4500, 4600, 4700, 4850, 5000,
- 5100, 5200, 5300, 5400, 5500, 5600, 5750, 5850,
- 5950, 6050, 6150, 6250, 6400, 6500, 6600, 6700,
- 6800, 6900, 6950, 6950, 7000, 7050, 7050, 7100,
- 7100, 7150, 7150, 7200, 7200, 7250, 7250, 7300,
- 7350, 7350, 7400, 7400, 7450, 7450
- } ;
-
- typedef struct trade_mark {
- char mk[90];
- } trade_mark;
-
- trade_mark mrk = {" UPS_Charge XFCN v1.0 Copyright 1988 by Sam Thornton * PO Box 123 * Fairfield NE 68938 "};
-
- #define CHARGE_LENGTH (sizeof(charge_table) / sizeof(struct _chgs))
-
- /* =================================================================== */
- /* MAIN PROCEDURE */
- /* =================================================================== */
-
- pascal void main (paramPtr)
- XCmdBlockPtr paramPtr;
-
- {
- char _cost[256];
- Handle answer;
- register int d_cost;
- register int f_zone;
- register int weight;
-
- RememberA0();
- SetUpA4();
-
- f_zone = atoi(*(paramPtr->params[0])); /* save the zone number */
-
- /* round fractional weights up to next even lb.,
- per UPS/FEX schedules */
- strcpy(_cost, "round(");
- strcat(_cost, *(paramPtr->params[1]));
- strcat(_cost, " + .49999)");
- CtoPstr(_cost);
- answer = EvalExpr(paramPtr, _cost);
- weight = atoi(*answer);
- DisposHandle(answer);
-
- /* sanity checks & evaluation */
- if (weight < 1 || weight > 70) goto PANIC;
- d_cost = FreightCharge(f_zone, (int)weight);
- if (d_cost == -1) goto PANIC;
-
- /* format the return */
- stci_d(_cost, d_cost, 7);
- f_zone = strlen(_cost);
- _cost[f_zone + 1] = '\0';
- _cost[f_zone] = _cost[f_zone - 1];
- _cost[f_zone - 1] = _cost[f_zone - 2];
- _cost[f_zone - 2] = '.';
- paramPtr->returnValue = NewHandle(f_zone + 2);
- strcpy( *paramPtr->returnValue, _cost);
- goto NOPANIC;
-
- PANIC:
- SysBeep(1);
- NOPANIC:
- RestoreA4();
- return;
- }
-
- /* =================================================================== */
- /* function to return a FREIGHT charge, given <f_zone>,<weight> */
- /* =================================================================== */
-
- int FreightCharge(f_zone,weight)
- register int f_zone, weight;
- {
- register int i,k;
- k = CHARGE_LENGTH;
-
- /* since there are so few main entries, we can do a simple
- serial search without losing too much time */
-
- for (i = 0; i < k; i++) {
- if (charge_table[i]._charge[0] == f_zone)
- return(charge_table[i]._charge[weight]);
- }
- return(-1); /* our error code for a bad zone number */
- }
-